package net.grandnature.android.morse.player;

import java.io.IOException;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class MorseGorillaPoolPlayer implements MorsePlayer {
	SoundPool spSound;
	int soundId_U = 0;
	int soundId_Ho = 1;
	int streamId_U = 0;
	int streamId_Ho = 1;

	int freq;
	
	public MorseGorillaPoolPlayer(double freq, int shortTime, Context context, int resU, int resHo){		

		this.freq = (int) freq;
        spSound = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
        soundId_U = spSound.load(context,resU , 1);
        soundId_Ho = spSound.load(context,resHo , 1);
	}

	@Override
	public void longSignal() {
		this.streamId_Ho = spSound.play(this.soundId_Ho, 1.0f, 1.0f, 1, 0, 1);
	}

	@Override
	public void shorSignal() {
		this.streamId_U = spSound.play(this.soundId_U, 1.0f, 1.0f, 1, 0, 1);
	}

	@Override
	public void silent(int length) {
		try {
			Thread.sleep(length * 200);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public void close() throws IOException {
		this.spSound.stop(streamId_U);
		this.spSound.stop(streamId_Ho);
	}
}
